Big-O Notation
O(1): constant growth; input size does not affect the number of operations significantly.
O(log n): logarithmic growth; the problem size is repeatedly reduced, as in binary search.
O(n): linear growth; work increases proportionally with input size.
O(n log n): common in efficient comparison-based sorting algorithms.
O(n²): quadratic growth; often caused by nested loops over the input.
Suppose you need to check if a user ID exists in an unsorted array of size n. What is the time complexity of a linear scan, and how would it change if the array were sorted?
If you have a hash map that gives O(1) average lookup, what does that mean for retrieving a value by key?
When you append an element to a dynamic array that occasionally resizes, what's the amortized time complexity?
Your recent feature added a nested loop to process a list of orders, and the latency doubled. Walk me through how you'd analyze the time complexity and identify the O(n²) part.
We switched from a binary search tree to a linked list for storing session tokens, and lookups got slower. Explain why the complexity changed from O(log n) to O(n).
During a code review you notice a function that sorts data using quicksort. Under what conditions could its performance degrade to O(n²), and how would you mitigate it?
Design a service that aggregates real‑time metrics from millions of devices. Which data structures and algorithmic complexities would you choose for ingest vs query paths, and why?
Your caching layer currently uses a simple array for LRU eviction, leading to O(n) updates. Propose a redesign that achieves O(1) operations and discuss trade‑offs.
When scaling a recommendation engine, you need to compute top‑k items per user. Compare using a heap (O(n log k)) vs sorting the entire list (O(n log n)) and justify your choice.
Our company is refactoring a legacy analytics pipeline that processes petabytes of logs daily. How would you evaluate and improve the overall algorithmic complexity across the pipeline to ensure it stays sub‑linear where possible?
We plan to migrate a monolithic search service to microservices. Discuss how Big‑O considerations influence the partitioning of indexing and query handling across services.
When introducing a new feature that requires joining two massive datasets, what architectural patterns can you use to avoid O(n²) blow‑up, and how would you measure success?